﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ePlanet.ArchiveMange.Enum;
using Microsoft.Practices.Unity;
using ePlanet.ArchiveMange.Services;
using Web.SystemConfig.WorkFlow;
using DreamBuilder.Core.Container;

namespace Web.Views.ArchiveManage
{
    public partial class SearchControl : System.Web.UI.UserControl
    {
        public event EventHandler SearchEvent;
        public string WhereString
        {
            get;
            set;
        }
        public IArchiveMenuService IArchiveMenuService;

        private ArchiveBaseType _baseArchiveType;

        protected ArchiveBaseType BaseArchiveType
        {
            get
            {
                if ((int)_baseArchiveType == 0)
                {
                    _baseArchiveType = (ArchiveBaseType)IArchiveMenuService.GetArchiveBaseIDById((int)CurrentArchiveKind);
                }
                return _baseArchiveType;
            }
        }

        private ArchiveTableEnum _currArchiveKind;
        /// <summary>
        /// 当前页的档案类型-派生类需要指定
        /// </summary>
        protected ArchiveTableEnum CurrentArchiveKind
        {
            get
            {
                if (_currArchiveKind == 0)
                {
                    if (Request.QueryString["archiveType"] != null)
                    {
                        //int baseTypeId = IArchiveMenuService.GetArchiveBaseIDById(int.Parse(Request.QueryString["archiveType"]));
                        int baseTypeId = int.Parse(Request.QueryString["archiveType"]);
                        _currArchiveKind = (ArchiveTableEnum)baseTypeId;
                    }
                    else
                    {
                        throw new Exception("档案类型不能为空");
                    }
                }
                return _currArchiveKind;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            IArchiveMenuService = UContainer.Resolve<IArchiveMenuService>();
            CommonSearchHelper.BuildSearchTable((int)BaseArchiveType, ref mySearchTable);
        }


        protected void BtnFilter_Click(object sender, EventArgs e)
        {
            this.WhereString = CommonSearchHelper.GetWhere((int)BaseArchiveType, mySearchTable);
            if (SearchEvent != null)
            {
                SearchEvent(this, e);
            }
        }
    }
}